package cn.com.gridinfo.sooc.core.course.classes.activity;

import android.content.Intent;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;

import com.jeremy.arad.utils.AnimUtil;

import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;
import cn.com.gridinfo.sooc.R;
import cn.com.gridinfo.sooc.base.BaseSoocActivity;
import cn.com.gridinfo.sooc.core.course.classes.adapter.KindsListAdapter;
import cn.com.gridinfo.sooc.core.course.classes.dao.CourseDao;
import cn.com.gridinfo.sooc.core.course.common.CodeConst;
import cn.com.gridinfo.sooc.utils.widget.UnScrollListView;

/**
 * 课程分类界面
 *
 * @author  jie.li
 */
public class CourseKindsActivity extends BaseSoocActivity {

    @InjectView(R.id.count_course)
    TextView countCourse;//全部课程的数目
    @InjectView(R.id.list_1)
    UnScrollListView list_kind;//分类1级目录
    CourseDao dao;//课程分类 dao

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.course_kinds_expandlist);
        ButterKnife.inject(this);
        dao = new CourseDao(this);
        dao.getCourseKindsList();
        list_kind.setFocusable(false);
    }

    //设置标题
    @Override
    public String setupToolBarTitle() {
        return "课程分类";
    }

    @Override
    public boolean setupToolBarLeftButton(ImageView leftButton) {
        return true;
    }

    //点击课程分类
    @OnClick(R.id.toolbar_leftbtn)
    void goBack(){
        finish();
        AnimUtil.intentSlidOut(this);
    }


    /**
     * 请求成功
     */
    @Override
    public void onRequestSuccess(int requestCode) {
        switch (requestCode){
            case CodeConst.COURSE_KINDS_MENU:
                //获取返回课程分类列表数据
                initView();
                break;
        }
    }


    /**
     * 初始化界面
     */
    void initView() {
        countCourse.setText(dao.getCourseKindsCount());
        KindsListAdapter adapter = new KindsListAdapter(this, dao.getCkList());
        list_kind.setAdapter(adapter);
    }

    /**
     * 全部课程区域的点击
     */
    @OnClick(R.id.allCourseContainer)
    void onclick() {
        //跳转到课程列表
        Intent i = new Intent(this, CourseListActivity.class);
        i.putExtra("yxid", "");
        i.putExtra("yxmc", "全部课程");
        startActivity(i);
        AnimUtil.intentSlidIn(this);
    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
        finish();
        AnimUtil.intentSlidOut(this);
    }
}
